
package com.idealighter.game.games.sirenniuniu.struct;

import com.idealighter.game.games.common.AbstractSeat;
import com.idealighter.game.games.common.SeatState;
import com.idealighter.game.games.common.niuniu.NiuNiuCard;
import com.idealighter.game.games.common.niuniu.NiuNiuCardsType;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledFuture;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 四人牛牛座位 .
 * 
 * @date 2016年1月20日 下午5:05:39
 *
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class SiRenNiuNiuSeat extends AbstractSeat {
  // 所属桌子
  private final SiRenNiuNiuTable table;
  // 是否是庄家
  private boolean dealer = false;
  // 是否叫庄,true:叫,false:不叫,null:没有叫过庄
  private Boolean callDealer = null;
  // 当前下注的筹码
  private long betedchips = 0;
  // 当前结算筹码
  private long billChips = 0;
  // 玩家的牌数据
  private final List<NiuNiuCard> cards = new ArrayList<>();
  // 玩家的牌最优牌(3+2)组合
  private final List<NiuNiuCard> bestCards = new ArrayList<>();
  // 当前牌型
  private NiuNiuCardsType cardsType = null;
  // 是否已经摊牌
  private boolean showdown = false;
  // 牛牛步骤(准备、叫庄、下注、摊牌)定时Future
  public ScheduledFuture<?> stepFuture = null;
  // 手牌大小(比庄家小设置为-1,比庄家到设置为1,庄家为0)
  private int power = 0;

  /**
   * 构造函数 .
   * 
   * @param order .
   * @param table .
   */
  public SiRenNiuNiuSeat(int order, SiRenNiuNiuTable table) {
    super(order);
    this.table = table;
  }

  /**
   * 重置座位数据 .
   */
  public void reset() {
    this.dealer = false;
    this.callDealer = null;
    this.betedchips = 0;
    this.billChips = 0;
    this.totalChips = 0;
    this.power = 0;
    this.cards.clear();
    this.bestCards.clear();
    this.cardsType = null;
    this.state = SeatState.SEATED;
    this.showdown = false;
    if (this.stepFuture != null) {
      this.stepFuture.cancel(false);
    }
  }

  public int getPower() {
    return power;
  }

  public void setPower(int power) {
    this.power = power;
  }

  /**
   * 重置座位数据除了totalChips .
   */
  public void resetButTotalChips() {
    long totalChips = this.totalChips;
    reset();
    this.totalChips = totalChips;
  }

  /**
   * 清空座位数据 .
   */
  public void clear() {
    this.playerId = 0;
    this.playerName = null;
    reset();

    if (table.players().size() <= 1) {
      boolean readied = table.isReadied();
      table.reset();
      table.setReadied(readied);
    }
  }

  @SuppressWarnings("unchecked")
  @Override
  public SiRenNiuNiuTable table() {
    return table;
  }
}
